<?php

namespace App\Http\Models;


use Illuminate\Database\Eloquent\Builder;

class Video extends BosModel
{
    protected static $unguarded = true;

    protected $table = 'videos';

    protected $bos_url = 'http://gz.bcebos.com/';

    protected $bosKeyPrefix = 'bym-admin/video/';

    public function scopeVideoTypeId(Builder $query,$video_type_id)
    {
        if ( $video_type_id ==0 ) return $query;

        return $query->where( 'video_type_id' , $video_type_id );
    }


    public function getUrlAttribute($url)
    {
        if (is_int(strpos($url,'http'))) return $url;
        if ( $url=='' ) return null;

        return $this->bos_url.$url ;
    }

    public function setPreviewImgAttribute($data)
    {
        if(!!$data) {
            $bosKey = $this->uploadImages($data,'video/preview_img/');
            $this->attributes['preview_img'] = $bosKey;
        }
    }

    public function getPreviewImgAttribute()
    {

        if (!!$this->attributes['preview_img'])
        {
            return $this->getUrl($this->attributes['preview_img']);
        }

    }

}
